<template>
	<view class="jc-nav-bar">
		<view class="bar_content">
			<uni-status-bar></uni-status-bar>
			<view class="content" @click="chooseCity">
				<u-icon name="map-fill" color='#666' size='36rpx'></u-icon>
				<view style="margin-left: 8rpx;width: 460rpx;" class="limitLineNumOfOne">{{ currentLocation.address || '定位中...' }}</view>
			</view>
		</view>
		
		<!-- 站位 -->
		<view class="home-navbar__placeholder">
			<uni-status-bar />
			<view class="home-navbar__placeholder-view" />
		</view>
	</view>
</template>

<script>
	import uniStatusBar from "@/components/uni-status-bar/uni-status-bar.vue";
	import {
		getLocation
	} from '@/common/utils/getLocation.js'
	export default{
		name: 'jc-nav-bar',
		components: {
			uniStatusBar
		},
		props:{
			fixed: {
				type: Boolean,
				default: true
			},
			title: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				currentLocation: {}
			}
		},
		mounted() {
			this.loadData()
		},
		methods:{
			back(){
				this.$emit('back')
			},
			chooseCity(){
				this.$emit('chooseCity')
			},
			loadData(){
				this.getLocation()
			},
			getLocation() {
				getLocation().then(res => {
					console.log('定位返回', res)
					if(res.code == '200'){
						var data = res.data || {}
						var address = data.formatted_addresses.recommend
						var currentLocation = {}
						currentLocation.address = address
						currentLocation.latitude = data.location.lat
						currentLocation.longitude = data.location.lng
						this.currentLocation = currentLocation
						this.$store.commit('currentLocation', currentLocation)
					}else{
						var currentLocation = {}
						currentLocation.address = '全国'
						currentLocation.latitude = 0
						currentLocation.longitude = 0
						this.currentLocation = currentLocation
						this.$store.commit('currentLocation', currentLocation)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	$bar_content_H : 44px;
	.jc-nav-bar{
		z-index: 9999999;
	}
	.bar_content{
		background-color: #FFF;
		width: 100%;
		position: fixed;
		top: 0;
		z-index: 10;
		.content{
			padding: 0 20rpx;
			height: 44px;
			display: flex;
			flex-direction: row;
			align-items: center;
			position: relative;
			.filter{
				display: flex;
				flex-direction: row;
				align-items: center;
				position: absolute;
				padding-left: 20rpx;
			}
			.title{
				color: #000000;
				font-size: 28rpx;
				margin: 0 auto;
			}
		}
	}
	.home-navbar__placeholder{
		width: 100%;
		.home-navbar__placeholder-view{
			width: 100%;
			height: $bar_content_H;
		}
	}
</style>
